<template>
    <DetailHeader />
    <StatisticsSearch class="search_box" :options="statisOptions" @submit="onSubmit" />
    <Quantity ref="QuantityRef" />
    <Statistics ref="StatisticsRef" />
</template>

<script setup lang="ts">
import { nextTick, reactive, ref } from 'vue';
import { getBasisInfo, getpartakeList, issueEnvelope, getExport } from '@/api/smartMarketing/order';
import { getStatis } from '@/api/smartMarketing/redEnvelopes';
import { useRoute } from 'vue-router';
import { getDay, DFormat } from '@/utils/utils';
import DetailHeader from '../components/DetailHeader.vue';
import Quantity from './components/Quantity.vue';
import Statistics from './components/Statistics.vue';
import StatisticsSearch from '@/components/zw/statistics-search/StatisticsSearch.vue';

const route = useRoute();
const QuantityRef: any = ref(null);
const StatisticsRef: any = ref(null);
const defaultParams = ref({
    create_at: [] //创建时间
});

const statisOptions = reactive([
    {
        label: '时间筛选',
        type: 'dateFilter'
    }
]);

const onSubmit = (data: any) => {
    defaultParams.value.create_at = data.times || [];
    nextTick(() => {
        if (data.times) {
            getData({});
        }
    });
};

const getData = async (v: any) => {
    if (v && v.create_at) defaultParams.value = { ...v };
    const params = {
        activity_id: route.query.id,
        ...defaultParams.value
    };
    const res = await getStatis(params);
    let quantity = {};
    const chartData = {
        date: [],
        red_num: [],
        red_amount: [],
        cust_num: []
    };
    quantity = res;
    res.stats_list.forEach((item: any) => {
        chartData.date.push(item.date);
        chartData.red_num.push(item.total_num);
        chartData.red_amount.push(item.total_amount);
        chartData.cust_num.push(item.total_cust);
    });
    QuantityRef.value.getData(quantity);
    StatisticsRef.value.getData(chartData);
};
</script>

<style lang="scss" scoped>
.search_box {
    margin-bottom: 16px;
}
</style>
